package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.bson.Document;
import org.bson.types.ObjectId;

import com.mongodb.client.MongoCursor;

import mongo.TeachingMaterialsTemplate;

/**
 * Servlet implementation class teacherMaterialsTemplateServlet
 */
@WebServlet(description = "teacherMaterialsTemplateServletProcess", urlPatterns = { "/teacher/teacherMaterialsTemplateServlet" })
public class teacherMaterialsTemplateServlet extends HttpServlet {
private TeachingMaterialsTemplate TeachingMaterialsTemplate = new TeachingMaterialsTemplate();
	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
	    response.setContentType("text/html;charset=UTF-8");
		
	    try {
    		MongoCursor<Document> result = TeachingMaterialsTemplate.list();
    		request.setAttribute("result", result);
    		request.getRequestDispatcher("teacherMaterialsTemplate.jsp").forward(request, response);
    		//response.sendRedirect("departList.jsp");
    		//TODO针对所属模块，返回到相对应的页面   
        }catch(Exception e){
            System.err.println( e.getClass().getName() + ": " + e.getMessage() );
          //TODO发生异常,跳转到对应页面
        }
	}

}
